﻿// -----------------------------------------------------------------------
// <copyright file="StringExtensions.cs" company="EPAM Systems">
////Copyright (c) EPAM Systems, 2012. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace MBOP.Helpers.Extensions
{
	#region Usings

	using System.Collections.Generic;
	using System.Text;

	#endregion

	/// <summary>
	/// Defines the extension of the System.String.
	/// </summary>
	public static class StringExtensions
	{
		/// <summary>
		/// Removes special chars from string.
		/// </summary>
		/// <param name="str">The input string.</param>
		/// <param name="specialChars">The specials chars.</param>
		/// <returns>The replaced string.</returns>
		public static string RemoveSpecialChars(this string str, IEnumerable<char> specialChars)
		{
			StringBuilder stringBuilder = new StringBuilder(str);

			foreach (char specialChar in specialChars)
			{
				int findingPos = str.IndexOf(specialChar, 0);

				while (findingPos != -1)
				{
					stringBuilder.Remove(findingPos, 1);
					findingPos = str.IndexOf(specialChar, findingPos);
				}
			}

			return stringBuilder.ToString();
		}
	}
}
